﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TankeWar.Properties;

namespace TankeWar
{
    //游戏状态枚举 Runing==0 GameOver==1
    enum GameState
    {
        Runing,
        GameOver
    }

    //游戏框架类
    internal class GameFramework
    {
        //图形处理对象
        public static Graphics g;
        //默认游戏状态是 运行
        private static GameState gamestate = GameState.Runing;
        
        //游戏开始
        public static void Start()
        {
            //完成音频初始化
            SoundManager.initSound();
            //游戏对象初始化
            GameObjectManager.Start();
            GameObjectManager.CreateMap();
            GameObjectManager.CreateMyTank();
            //播放启动音乐
            SoundManager.PlayStart();
        }
        //游戏更新
        public static void Update()
        {
            if (gamestate == GameState.Runing)
            {
                GameObjectManager.Update();
            }
            else if (gamestate == GameState.GameOver)
            {
                GameOverUpdate();
            }

        }
        //更新游戏结束状态
        public static void GameOverUpdate()
        {
            //读取游戏结束图像
            Bitmap bmp = Resources.GameOver;
            bmp.MakeTransparent(Color.Black);
            int x = 450/2 - Resources.GameOver.Width/2;
            int y = 450 / 2 - Resources.GameOver.Height / 2;
            g.DrawImage(bmp, x, y);
        }
        //改变成结束态
        public static void ChangeToGameOver()
        {
            gamestate = GameState.GameOver;
        }

    }
}
